package com.作业.Day19;


/**
 *  编写多线程程序，模拟多个人通过一个山洞的模拟。
 * 	这个山洞每次只能通过一个人，每个人通过山洞的时间为5秒，
 * 	有10个人同时准备过此山洞，显示每次通过山洞人的姓名和顺序。
 *
 *
 */
public class Test4 {
    public static void main(String[] args) {
        new Thread(new ThrowingHole(),"1").start();
        new Thread(new ThrowingHole(),"2").start();
        new Thread(new ThrowingHole(),"3").start();
        new Thread(new ThrowingHole(),"4").start();
        new Thread(new ThrowingHole(),"5").start();
        new Thread(new ThrowingHole(),"6").start();
        new Thread(new ThrowingHole(),"7").start();
        new Thread(new ThrowingHole(),"8").start();
        new Thread(new ThrowingHole(),"9").start();
        new Thread(new ThrowingHole(),"10").start();

    }
}
class ThrowingHole implements Runnable {

    @Override
    public void run() {
        synchronized ( this){
            System.out.println(Thread.currentThread().getName() + "开始通过山洞");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}